import type * as AgentTypeInfo from "@@/apis/intelligent/type"
import type { AxiosResponse } from "node_modules/axios/index.d.cts"
import type * as TypeInfo from "./type"
import { request } from "@/http/axios"
import { isEmpty } from "lodash-es"

const baseURL = import.meta.env.VITE_TRAIN_API

// 推演创建模式
export function createImportTask(task_id: string) {
  return request({
    baseURL,
    url: `/toksim/reinforcement/task/trained/import/${task_id}`,
    method: "post"
  })
}

// 开始任务
export function startTaskApi(taskId: string) {
  return request({
    baseURL,
    url: `/toksim/reinforcement/task/start/${taskId}`,
    method: "post"
  })
}
// 暂停任务
export function pauseTaskApi(taskId: string) {
  return request({
    baseURL,
    url: `/toksim/reinforcement/task/stop/${taskId}`,
    method: "post"
  })
}
// 结束任务
export function endTaskApi(taskId: string) {
  return request({
    baseURL,
    url: `/toksim/reinforcement/task/end/${taskId}`,
    method: "post"
  })
}
// 保存文件
export function saveFileApi(taskId: string, data: {
  process_file_id: string
  associate_id: string
}) {
  return request({
    baseURL,
    url: `/toksim/resource/process/${taskId}/agent/save`,
    method: "post",
    data
  })
}
// 删除任务过程文件数据
export function deleteTaskProcessFileApi(taskId: string) {
  return request({
    baseURL,
    url: `/toksim/resource/process/${taskId}/delete`,
    method: "post"
  })
}
// 下载任务过程文件数据
export function downloadTaskProcessFileApi(taskId: string, data: any) {
  return request<AxiosResponse>({
    baseURL,
    headers: {
      "Content-Type": "application/octet-stream"
    },
    responseType: "blob",
    url: `/toksim/resource/process/${taskId}/download`,
    method: "post",
    data
  })
}
// 清空任务过程文件数据
export function clearTaskProcessFileApi(taskId: string, type: string) {
  return request({
    baseURL,
    url: `/toksim/resource/process/${taskId}/${type}/empty`,
    method: "post"
  })
}
// 检索任务文件
export function searchTaskFileApi(taskId: string, data: any) {
  return request<TypeInfo.FilePageTableResponseData>({
    baseURL,
    url: `/toksim/resource/process/${taskId}/search`,
    method: "post",
    data
  })
}
// 获取任务过程数据
export function getTaskProcessDataApi(taskId: string) {
  return request<TypeInfo.TaskProcessDataResponseData>({
    baseURL,
    url: `/toksim/reinforcement/task/data/get`,
    method: "post",
    data: {
      task_id: taskId
    }
  })
}
// 检索任务
export function searchTaskApi(params: TypeInfo.TableRequestData) {
  if (isEmpty(params.project_id)) {
    delete params.project_id
  }
  return request<TypeInfo.PageTableResponseData>({
    baseURL,
    url: "/toksim/reinforcement/task/search",
    method: "post",
    data: params
  })
}
// 删除任务
export function deleteTaskApi(data: any) {
  return request({
    baseURL,
    url: `/toksim/reinforcement/task/delete`,
    method: "post",
    data
  })
}
// 根据id查询任务基本信息
export function getTaskInfoApi(taskId: string) {
  return request<TypeInfo.TaskInfoResponseData>({
    baseURL,
    url: `/toksim/reinforcement/task/get/${taskId}`,
    method: "get"
  })
}
// 创建任务
export function createTaskApi(data: TypeInfo.EditInfrenceBasicInfo | TypeInfo.EditTrainBasicInfo) {
  if (isEmpty(data.project_id)) {
    delete data.project_id
  }
  return request<TypeInfo.TaskCreateResponseData>({
    baseURL,
    url: "/toksim/reinforcement/task/create",
    method: "post",
    data
  })
}
// 更新任务
export function updateTaskApi(data: TypeInfo.EditInfrenceBasicInfo | TypeInfo.EditTrainBasicInfo) {
  if (isEmpty(data.project_id)) {
    delete data.project_id
  }
  return request<TypeInfo.TaskCreateResponseData>({
    baseURL,
    url: "/toksim/reinforcement/task/edit",
    method: "post",
    data
  })
}
// 查询智能体及训练出的智能体
export function searchAgentAndTrainedApi(params: AgentTypeInfo.TableRequestData) {
  if (isEmpty(params.project_id)) {
    delete params.project_id
  }
  return request<AgentTypeInfo.AgentAndTrainResponseData>({
    baseURL,
    url: "/toksim/resource/agent/search_and_trained",
    method: "post",
    data: params
  })
}
//根据想定id查询所有实体名称
export function getEntityNameListApi(scnId: string) {
  return request<TypeInfo.FilePageTableResponseData>({
    baseURL,
    url: `/casia/scenario/manage/getEntityNameList/{scnId}`,
    method: "get",
  })
}

// 获取推演回放数据
export function getHistoryApi(taskId: string, taskNumber: string) {
  return request({
    baseURL,
    url: `/toksim/task/history/get`,
    method: "get",
    params: {
      task_id: taskId,
      task_number: taskNumber
    }
  })
}
// 删除任务历史记录
export function deleteHistoryApi(taskId: string, taskNumber: string, roundNumber: string) {
  return request({
    baseURL,
    url: `/toksim/task/history/delete`,
    method: "DELETE",
    data: {
      task_id: taskId,
      task_number: taskNumber,
      round_number: roundNumber
    }
  })
}
// 获取任务局数及评估指标
export function getTaskProcessEvalApi(taskId: string, taskNumber: string) {
  return request({
    baseURL,
    url: `/toksim/task/history/process_eval/get`,
    method: "get",
    params: {
      task_id: taskId,
      task_number: taskNumber
    }
  })
}
// 获取任务态势
export function getTaskSituationApi(taskId: string, taskNumber: string, roundNumber: string) {
  return request({
    baseURL,
    url: `/toksim/task/history/situation/get`,
    method: "get",
    params: {
      task_id: taskId,
      task_number: taskNumber,
      round_number: roundNumber
    }
  })
}
// 获取任务采集数据
export function getTaskCollectDataApi(taskId: string, taskNumber: string, roundNumber: string) {
  return request({
    baseURL,
    url: `/toksim/task/history/data_collection/get`,
    method: "get",
    params: {
      task_id: taskId,
      task_number: taskNumber,
      round_number: roundNumber
    }
  })
}

// 条件查询
export function getProcessevalSearchApi(data: any) {
  return request({
    baseURL,
    url: `/toksim/task/process_eval/search`,
    method: "post",
    data
  })
}

